﻿using System;

namespace BSPortal.Usercontrol
{
    public partial class Header : System.Web.UI.UserControl
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            var control = (HtmlContent)LoadControl("HtmlContent.ascx");
            control.HtmlContentId = short.Parse(Common.GetValueInAppSetting("QucickContact", "2"));
            supportContent.Controls.Add(control);
            ShowLogin();
        }

        private void ShowLogin()
        {
            if (Session["Username"] != null && (bool) Session["IsLogin"])
            {
                lblUsername.Text = "Chào " + System.Web.HttpContext.Current.Session["Username"];
                User login = Common.GetClientService().GetUserById(System.Web.HttpContext.Current.Session["Username"].ToString());
                if (login.Type != 0)
                    AdminLink.Visible = false;
                hpLinkLogout.Visible = true;
                hpLinkLogin.Visible = false;
                hpLinkCheckOut.Visible = false;
            }
            else
            {
                AdminLink.Visible = false;
                hpLinkLogout.Visible = false;
                hpLinkLogin.Visible = true;
                hpLinkCheckOut.Visible = true;
            }
        }

        protected void hpLinkLogin_Click(object sender, EventArgs e)
        {
            MainService mainService = Common.GetClientService();
            int logout = mainService.Logout();
            Response.Redirect("dang-nhap.html");
        }

        protected void hpLinkCheckOut_Click(object sender, EventArgs e)
        {
            Response.Redirect("dang-ky.html");
        }
    }
}